/**
 * Created by Administrator on 2017/12/9.
 */
//$("header>a.goBack").click(function(){
//    window.history.go(-1)
//});
var xpHome =new Vue({
    el:"#app",
    data:{
        couponList:[],//我的优惠券
        getCoupon:{},//领取优惠券
        noUseList:null,//未使用列表
    },
    methods: {
        getDate: function (time) {
            return nUtils.dateType(time);
        },
        getPrice: function (price) { //替换
            if (price) {
                var prices = price.replace(".00", "");
                return prices;
            }
        },
        changeTab: function (status) { //切换优惠券状态
            xpHome.getCouponInfo(status)
        },
        getCouponInfo: function (status) {//我的优惠券数据
            var data = {
                "userid": userInfo.userid,
                "access_token": userInfo.access_token,
                "data[type]": status//三种
            }
            var url = nUrls.myCoupon;
            if (status == 3) {
                var data = {
                    "userid": userInfo.userid,
                    "access_token": userInfo.access_token,
                    "data[type]": 3//三种
                }
                url = nUrls.getCoupon;
            }
            $.ajax({
                url: url,
                type: "POST",
                data: data,
                success: function (data) {
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        xpHome.couponList = result.data;
                        console.log(xpHome.couponList)
                    }
                },
                error: function () {
                    console.log("获取信息出错");
                }
            })
        },
        getCouponStatus: function (order, end_time) {
            var status = "";
            var date = Date.parse(new Date());
            console.log("--date-", date)
            if (order == 1) {
                status = "已使用";
            } else if (order == 0) {
                if (end_time < date) {
                    status = "已过期";
                }
            }

            switch (order) {
                case "0":
                    status = "立即使用";
                    break;
                case "1":
                    status = "已使用";
                    break;
            }
            return status;
        },
        goGoods_detail: function (idx) {
            if (xpHome.couponList[idx].is_used == 0) {
                window.location.href = "http://www.pooai.cn/wx/frontend/web/index.php?r=site/site/gowxd"
            } else {
                return
            }
        }
    }
})
$(function(){
    xpHome.getCouponInfo("0")
})
var tab = new auiTab({
    element:document.getElementById("tab"),
    index:1,
    repeatClick:false
},function(ret){
    // console.log(ret);

});
